local skel = fk.CreateSkill {
  name = "emo__kekedi",
  tags = {Skill.Switch},
}

skel:addEffect("active", {
  anim_type = "control",
  card_num = 0,
  target_num = 1,
  prompt = function (self, player, selected_cards, selected_targets)
    return "#emo__kekedi_"..player:getSwitchSkillState(skel.name, false, true)
  end,
  target_filter = function (self, player, to_select, selected)
    return #selected == 0
  end,
  can_use = function (self, player)
    return player:usedSkillTimes(skel.name, Player.HistoryPhase) < 2
  end,
  times = function (self, player)
    return 2 - player:usedSkillTimes(skel.name, Player.HistoryPhase)
  end,
  on_use = function (self, room, use)
    local player, to = use.from, use.tos[1]
    if player:getSwitchSkillState(skel.name, true) == fk.SwitchYang then
      room:setPlayerMark(to, "@@kurumi_aleph", 1)
      player:drawCards(1, skel.name)
    else
      room:setPlayerMark(to, "@@kurumi_bet", 1)
    end
  end,
})

skel:addEffect(fk.CardUsing, {
  is_delay_effect = true,
  mute = true,
  can_trigger = function (self, event, target, player, data)
    return target:getMark("@@kurumi_bet") ~= 0 and target == player
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    if target:isNude() or #player.room:askToDiscard(target, {
      min_num = 1, max_num = 1, skill_name = skel.name, cancelable = true, include_equip = true,
      pattern = data.card.trueName, prompt = "#emo__kekedi-discard:::"..data.card.trueName,
    }) == 0 then
      data:removeAllTargets()
      data.toCard = nil
    end
  end,
})

skel:addEffect(fk.TurnEnd, {
  late_refresh = true,
  can_refresh = function (self, event, target, player, data)
    return target == player and (player:getMark("@@kurumi_aleph") ~= 0 or player:getMark("@@kurumi_bet") ~= 0)
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:setPlayerMark(player, "@@kurumi_aleph", 0)
    player.room:setPlayerMark(player, "@@kurumi_bet", 0)
  end,
})

skel:addEffect("targetmod", {
  residue_func = function (self, player, skill, scope, card, to)
    if player and player:getMark("@@kurumi_aleph") ~= 0 and skill and skill.trueName == "slash_skill" then
      return 2
    end
  end,
})

Fk:loadTranslationTable{
  ["emo__kekedi"] = "刻刻帝",
  [":emo__kekedi"] = "转换技，出牌阶段限两次，阳：使用一之弹，令一名角色摸1张牌，使用【杀】上限+2，直到其回合结束；阴：使用二之弹，令一名角色，使用一张牌时需弃置一张同名牌，否则无效，直到其回合结束。",

  [":emo__kekedi_yang"] = "转换技，出牌阶段限两次，<font color=\"#E0DB2F\">阳：使用一之弹，令一名角色摸1张牌，使用【杀】上限+2，直到其回合结束；</font>阴：使用二之弹，令一名角色，使用一张牌时需弃置一张同名牌，否则无效，直到其回合结束。",
  [":emo__kekedi_yin"] = "转换技，出牌阶段限两次，阳：使用一之弹，令一名角色摸1张牌，使用【杀】上限+2，直到其回合结束；<font color=\"#E0DB2F\">阴：使用二之弹，令一名角色，使用一张牌时需弃置一张同名牌，否则无效，直到其回合结束。</font>",
  ["#emo__kekedi_yang"] = "使用一之弹，令一名角色摸1张牌，使用【杀】上限+2",
  ["#emo__kekedi_yin"] = "使用二之弹，令一名角色，使用一张牌时需弃置一张同名牌，否则无效",

  ["@@kurumi_aleph"] = "<font color=\"#FF3300\">一之弹</font>",
  ["@@kurumi_bet"] = "<font color=\"#FFFF66\">二之弹</font>",
  ["#emo__kekedi-discard"] = "刻刻帝：你需弃置一张【%arg】，否则你使用的%arg无效",
  [""] = "",
}


return skel
